R environment

Before the first lecture, we need to set up your computing environment.

Agenda

By the end of this pre-lecture, you will be able to …

  • Download & Install R
  • Download & Install R-studio
  • Your first command

Hello, World!

Learning to write a computer program to print Hello, World! to your screen is often the first thing you learn in programming.

To make sure you are ready use a computer program (R) to work with data, this lab will set you up to use R to print this sentence to your screen.

Computational toolkit:

  1. R: The programming language you’ll learn in this course.

  2. RStudio: The software you’ll use to write R code in.

Heads up!

R is the name of the programming language itself and RStudio is a convenient interface.

Download and Install R

R is available through the web page of The Comprehensive R Archive Network (CRAN).

The top of the web page provides three links for downloading R. Follow the link that describes your operating system: Windows, Mac, or Linux. Complete instructions area available from rstudio-education, with key steps listed below.

R: Windows

To install R on Windows, click the “Download R for Windows” link.

Then click the “base” link.

Next, click the first link at the top of the new page. This link should say something like “Download R 4.5.1 for Windows.” (Note: 4.5.1 will be replaced by the most current version of R.)

The link downloads an installer program, which installs the most up-to-date version of R for Windows.

Run this program and step through the installation wizard that appears. The wizard will install R into your program files folders and place a shortcut in your Start menu. You’ll need to have all of the appropriate administration privileges to install new software on your machine.

WINDOWS HELP VIDEO

If you prefer to watch a video or would like more details, I recommend Windows users watch this video. Or, you can search out a video yourself if you prefer.

R: Mac

To install R on a Mac, click the “Download R for Mac” link. Next, click on the R-4.5.1 package link (or the package link for the most current release of R). An installer will download to guide you through the installation process. The installer lets you customize your installation, but the defaults will be suitable for most users. If your computer requires a password before installing new progams, you’ll need it here.

MAC HELP VIDEO

If you prefer to watch a video or would like more details, I recommend Mac users watch this video. Or, you can search out a video yourself if you prefer.

Download & Install R-studio

After you have installed R, you are ready to begin this section! In your web browser (e.g., Chrome, Safari, Edge), go to: https://posit.co/download/rstudio-desktop/

Since you’ve already installed R, you’re reading for step 2. Click on the “DOWNLOAD RSTUDIO DESKTOP FOR WINDOWS/MAC0S” button. This is a big file, so it may take a few minutes to download. Once it’s downloaded, click on the file to install it.

Your first command

Open RStudio

Once you’ve installed R and RStudio, locate RStudio and open it.

Windows Users: you’ll find RStudio by either using the Windows search bar or clicking on the Windows start button and then typing “RStudio.”

Mac Users: RStudio will can be found in your launchpad, or you can drag and drop it to your applications folder. Click “Open” when asked if you want to open the program that has been downloaded from the internet. If a pop-up asks if you want to install “git” tools, you can click “Cancel” (not necessary for this class).

print()

Put your cursor next to the > and type: print("Hello, World!) Then press enter. You should see your sentence appear below it.

print("Hello, World!")
[1] "Hello, World!"
Heads Up!

print is case-sensitive (e.g., don’t capitalize “p”). Include the parentheses and quotes. Move your cursor to after the last “)” before hitting “Enter”.

Congrats! You’re ready to begin analyzing data!